﻿using CorpStore.Common;
using StoreHelper;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Media.Imaging;

namespace CorpStore.Models
{
    /// <summary>
    /// This is a CorpStore modern app internal class which is used to represent
    /// an individual screenshot.  It contains not only the filename of a 
    /// screenshot but also the BitmapImage representation of that file.
    /// </summary>
    public class ScreenshotInfo : BindableBase
    {
        private string filename;
        public string Filename
        {
            get { return filename; }
            set { filename = value; OnPropertyChanged(); OnPropertyChanged("ScreenshotImage"); }
        }

        private BitmapImage screenshotImage;
        public BitmapImage ScreenshotImage
        {
            get
            {
                if (screenshotImage == null)
                {
                    screenshotImage = new BitmapImage();

                    if (filename.IndexOf("://") == -1)
                        GenIO.SetImageFromLocalFolderAsync(screenshotImage, getFnWithoutLocalFolder(filename));
                    else
                        GenIO.SetImageFromUriAsync(screenshotImage, filename);
                }

                return screenshotImage;
            }
        }


        public string Description { get; set; }

        public ScreenshotInfo() { }

        public ScreenshotInfo(string filename, string description)
        {
            this.Filename = filename;
            this.Description = description;
        }

        private string getFnWithoutLocalFolder(string fn)
        {
            return string.Format("AppFiles\\{0}", Path.GetFileName(fn));
        }

    }
}
